-
Notifications
You must be signed in to change notification settings - Fork 405
Async BumpTransactionEventHandler #3752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
👋 Thanks for assigning @tnull as a reviewer! |
d9b1c75
to
873516b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3752 +/- ##
========================================
Coverage 89.78% 89.78%
========================================
Files 159 159
Lines 128672 128778 +106
Branches 128672 128778 +106
========================================
+ Hits 115522 115623 +101
- Misses 10476 10478 +2
- Partials 2674 2677 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
4b4b898
to
3816c66
Compare
1a86521
to
e1509f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first / quickish pass. Generally looks good so far.
lightning/Cargo.toml
Outdated
@@ -48,12 +48,14 @@ backtrace = { version = "0.3", optional = true } | |||
|
|||
libm = { version = "0.2", default-features = false } | |||
inventory = { version = "0.3", optional = true } | |||
tokio = { version = "1.35", features = [ "macros", "rt" ], optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please set default-features = false
here and below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added. Why is this? I looked at the tokio crate and it seems there are no default features?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's 'best practice' and will also make sure we'd not add arbitrary dependencies if tokio
decided to add default features in some release.
*commitment_tx_fee_satoshis, | ||
anchor_descriptor, | ||
) { | ||
if let Err(_) = self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO these would be a bit more readable if we did the the whole call including .await
on a separate line and then simply did if res.is_err() { .. }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it, but I don't think it is an improvement with that temp var.
let res = self
.handle_channel_close(
*claim_id,
*package_target_feerate_sat_per_1000_weight,
commitment_tx,
*commitment_tx_fee_satoshis,
anchor_descriptor,
)
.await;
if res.is_err() {
log_error!(
self.logger,
"Failed bumping commitment transaction fee for {}",
commitment_tx.compute_txid()
);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also tried with map_err
, but that doesn't work all that well with the parent fn without a return result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also tried with
map_err
, but that doesn't work all that well with the parent fn without a return result.
How about:
self.handle_channel_close(
*claim_id,
*package_target_feerate_sat_per_1000_weight,
commitment_tx,
*commitment_tx_fee_satoshis,
anchor_descriptor,
)
.await
.unwrap_or_else(|_| {
log_error!(
self.logger,
"Failed bumping commitment transaction fee for {}",
commitment_tx.compute_txid()
);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this is nicer. Wasn't aware of the unwrap_or_else on result. Updated.
lightning/src/ln/functional_tests.rs
Outdated
#[allow(clippy::expect_used, clippy::diverging_sub_expression)] | ||
{ | ||
return tokio::runtime::Builder::new_current_thread() | ||
.enable_all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I don't think we need to enable_all
here, could just actually enable features we need. Same goes for all the tests that use [tokio::test]
, although not sure if it makes a big difference in practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just expanded the macro. Can make customizations, but maybe it is better to keep to the original expansion? Also if it doesn't matter in practice...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no strong opinion. If we increase the number of tests using tokio, we might want to some benchmarks though, as the runtime of cargo test
accumulates over time, so every second we can squeeze out of it would be appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed then. If we get more of these xtests, we might need to duplicate the macro or something like that.
let configs = [(false, false), (false, true), (true, false), (true, true)]; | ||
let mut last_err = None; | ||
for (force_conflicting_utxo_spend, tolerate_high_network_feerates) in configs { | ||
log_debug!( | ||
self.logger, | ||
"Attempting coin selection targeting {} sat/kW (force_conflicting_utxo_spend = {}, tolerate_high_network_feerates = {})", | ||
target_feerate_sat_per_1000_weight, | ||
force_conflicting_utxo_spend, | ||
tolerate_high_network_feerates | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Indent off here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the indent off. The closing parenthesis?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the parenthesis and all arguments of log_debug
too (they need to be indented by one tab).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the problem anymore in the diff now, but github still shows it on the old code fragment? In my IDE it all looks good with tabs, so I think it is solved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, happened in the next commit. Fixed now.
👋 The first review has been submitted! Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer. |
e1509f1
to
991d505
Compare
991d505
to
7f67bb0
Compare
Async closures are complicated. Preparatory commit.
7f67bb0
to
6fd5e5b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did another pass. I have yet to verify it doesn't break anything in LDK Node, but otherwise LGTM (mod the pending comments here).
log_error!( | ||
self.logger, | ||
"Failed bumping commitment transaction fee for {}", | ||
"Failed bumping channel close transaction for {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why was the previous message wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ai ai ai I am so embarrassed here. This and the other ones are LLM completions 😞
let configs = [(false, false), (false, true), (true, false), (true, true)]; | ||
let mut last_err = None; | ||
for (force_conflicting_utxo_spend, tolerate_high_network_feerates) in configs { | ||
log_debug!( | ||
self.logger, | ||
"Attempting coin selection targeting {} sat/kW (force_conflicting_utxo_spend = {}, tolerate_high_network_feerates = {})", | ||
target_feerate_sat_per_1000_weight, | ||
force_conflicting_utxo_spend, | ||
tolerate_high_network_feerates | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert methods that need to be async when the wallet traits become async.
6fd5e5b
to
96b704f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from my side, mod one (likely) LLM-induced change that you overlooked.
It seems that the compiler doesn't recognize the drop and complains that the mutex crosses an await (introduced in later commit), even though it doesn't.
Async closures are complicated. Preparatory commit.
Changes the CoinSelectionSource and WalletSource traits to be async and provides WalletSourceSyncWrapper to as a helper for users that want to implement a sync wallet source. TestWalletSource is kept sync, to prevent a cascade of async conversions in tests.
96b704f
to
91bc001
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, mod second reviewer feedback
Converts
BumpTransactionEventHandler
to async.Changes the
CoinSelectionSource
andWalletSource
traits to be async and providesWalletSourceSyncWrapper
as a helper for users that want to implement a sync wallet source.TestWalletSource
is kept sync, to prevent a cascade of async conversions in tests.Fixes #3540